﻿Imports DTO
Imports System.Data.SqlClient
Public Class TIECCUOIDAO
    Private ketnoi As New DAO.connect()
    'Public Function loadTIECCUOI() As DataTable
    '    'ketnoi.OpenConnection()
    '    'Dim dtnv As New DataTable()
    '    'Dim chuoi As String = "select * from TIECCUOI"
    '    'dtnv = ketnoi.getDataTable(chuoi)
    '    'ketnoi.CloseConnection()
    '    'Return dtnv
    'End Function
    Private Function Sqlcommand_THEM(ByVal MATIECCUOI As Integer, ByVal TENCHURE As String, ByVal TENCODAU As String, ByVal DIENTHOAI As Integer, ByVal NGAYCUOI As Date, ByVal CA As String, ByVal MASANH As Integer, ByVal TIENDATCOC As Double, ByVal SOLUONGBANDAT As Integer, ByVal SOBANDUTRU As Integer) As Integer
        ketnoi.OpenConnection()
        Dim i As Integer = 0

        Dim sqlcmd As New SqlCommand("Stor_THEM_TIECCUOI", ketnoi.getConnection)

        sqlcmd.CommandType = CommandType.StoredProcedure
        'sqlcmd.Parameters.Add("@mode", SqlDbType.Int).Value = mode;
        sqlcmd.Parameters.Add("@MATIECCUOI", SqlDbType.Int).Value = MATIECCUOI
        sqlcmd.Parameters.Add("@TENCHURE", SqlDbType.NVarChar).Value = TENCHURE
        sqlcmd.Parameters.Add("@TENCODAU", SqlDbType.NVarChar).Value = TENCODAU
        sqlcmd.Parameters.Add("@DIENTHOAI", SqlDbType.Int).Value = DIENTHOAI
        sqlcmd.Parameters.Add("@NGAYCUOI", SqlDbType.Date).Value = NGAYCUOI
        sqlcmd.Parameters.Add("@CA", SqlDbType.NVarChar).Value = CA
        sqlcmd.Parameters.Add("@MASANH", SqlDbType.Int).Value = MASANH
        sqlcmd.Parameters.Add("@TIENDATCOC", SqlDbType.Float).Value = TIENDATCOC
        sqlcmd.Parameters.Add("@SOLUONGBANDAT", SqlDbType.Int).Value = SOLUONGBANDAT
        sqlcmd.Parameters.Add("@SOBANDUTRU", SqlDbType.Int).Value = SOBANDUTRU

        i = sqlcmd.ExecuteNonQuery()
        ketnoi.CloseConnection()
        Return i
    End Function
    Public Function them_TIECCUOI(ByVal dto As TIECCUOIDTO)
        ketnoi.OpenConnection()
        'Dim dto As New LOAITIECCUOIDTO()
        If Sqlcommand_THEM(dto.MATIECCUOI, dto.TENCHURE, dto.TENCODAU, dto.DIENTHOAI, dto.NGAYCUOI, dto.CA, dto.MASANH, dto.TIENDATCOC, dto.SOLUONGBANDAT, dto.SOBANDUTRU) <> 0 Then
            ketnoi.CloseConnection()
            Return True
        End If
        ketnoi.CloseConnection()
        Return False
    End Function

    Private Function Sqlcommand_capnhat(ByVal MATIECCUOI As Integer, ByVal TENCHURE As String, ByVal TENCODAU As String, ByVal DIENTHOAI As Integer, ByVal NGAYCUOI As Date, ByVal CA As String, ByVal MASANH As Integer, ByVal TIENDATCOC As Double, ByVal SOLUONGBANDAT As Integer, ByVal SOBANDUTRU As Integer) As Integer
        ketnoi.OpenConnection()
        Dim i As Integer = 0

        Dim sqlcmd As New SqlCommand("STOR_CAPNHAT_TIECCUOI", ketnoi.getConnection)
        sqlcmd.CommandType = CommandType.StoredProcedure


        'sqlcmd.Parameters.Add("@mode", SqlDbType.Int).Value = mode;
        sqlcmd.Parameters.Add("@MATIECCUOI", SqlDbType.Int).Value = MATIECCUOI
        sqlcmd.Parameters.Add("@TENCHURE", SqlDbType.NVarChar).Value = TENCHURE
        sqlcmd.Parameters.Add("@TENCODAU", SqlDbType.NVarChar).Value = TENCODAU
        sqlcmd.Parameters.Add("@DIENTHOAI", SqlDbType.Int).Value = DIENTHOAI
        sqlcmd.Parameters.Add("@NGAYCUOI", SqlDbType.Date).Value = NGAYCUOI
        sqlcmd.Parameters.Add("@CA", SqlDbType.NVarChar).Value = CA
        sqlcmd.Parameters.Add("@MASANH", SqlDbType.Int).Value = MASANH
        sqlcmd.Parameters.Add("@TIENDATCOC", SqlDbType.Float).Value = TIENDATCOC
        sqlcmd.Parameters.Add("@SOLUONGBANDAT", SqlDbType.Int).Value = SOLUONGBANDAT
        sqlcmd.Parameters.Add("@SOBANDUTRU", SqlDbType.Int).Value = SOBANDUTRU


        i = sqlcmd.ExecuteNonQuery()
        ketnoi.CloseConnection()
        Return i
    End Function
    Public Function capnhat_TIECCUOI(ByVal dto As TIECCUOIDTO) As Boolean
        ketnoi.OpenConnection()
        If Sqlcommand_capnhat(dto.MATIECCUOI, dto.TENCHURE, dto.TENCODAU, dto.DIENTHOAI, dto.NGAYCUOI, dto.CA, dto.MASANH, dto.TIENDATCOC, dto.SOLUONGBANDAT, dto.SOBANDUTRU) <> 0 Then
            ketnoi.CloseConnection()
            Return True
        End If
        ketnoi.CloseConnection()
        Return False

    End Function

    Private Function Sqlcommand_XOA(ByVal MATIECCUOI As Integer) As Integer
        ketnoi.OpenConnection()
        Dim i As Integer = 0

        Dim sqlcmd As New SqlCommand("Stor_XOA_TIECCUOI", ketnoi.getConnection)
        sqlcmd.CommandType = CommandType.StoredProcedure
        sqlcmd.Parameters.Add("@MATIECCUOI", SqlDbType.Int).Value = MATIECCUOI

        i = sqlcmd.ExecuteNonQuery()
        ketnoi.CloseConnection()
        Return i
    End Function
    Public Function xoa_TIECCUOI(ByVal dto As TIECCUOIDTO) As Boolean
        ketnoi.OpenConnection()
        If Sqlcommand_XOA(dto.MATIECCUOI) <> 0 Then
            ketnoi.CloseConnection()
            Return True
        End If
        ketnoi.CloseConnection()
        Return False

    End Function

End Class
